/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin			*/
/*	Project:	GlbCloud			*/
/*	Author:		gong_libin			*/
/*	Date:		2012_01_08			*/
/*	File:		MrFile.h			*/
/********************************************************/

#ifndef	_MRFILE_H
#define	_MRFILE_H

#include "MrGlobal.h"
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>

#define	MR_S_SET			SEEK_SET
#define	MR_S_END			SEEK_END
#define	MR_S_CUR			SEEK_CUR

#define	MR_F_RDLCK			F_RDLCK
#define	MR_F_WRLCK			F_WRLCK
#define	MR_F_UNLCK			F_UNLCK

#define	MR_F_SETLK			F_SETLK
#define	MR_F_SETLKW			F_SETLKW

#define	MR_O_EXCL			O_EXCL
#define	MR_O_CREATE			O_CREAT

#define	MR_O_RDWR			O_RDWR
#define	MR_O_RDONLY			O_RDONLY
#define	MR_O_WRONLY			O_WRONLY
#define	MR_O_APPEND			O_APPEND

#define	MR_P_READ			PROT_READ
#define	MR_P_WRITE			PROT_WRITE

#define	MR_M_SHARED			MAP_SHARED
#define	MR_M_PRIVATE			MAP_PRIVATE

class CMrFile
{
public:
	CMrFile();
	virtual ~CMrFile();

	void MrFileClose();
	void* MrFileGetFile();
	ULONG MrFileGetSize();
	int MrFileMunmap(ULONG ulSize);
	int MrFileCreate(char* pszFile);
	int MrFileDelete(char* pszFile);
	int MrFileOpen(char* pszFile, int iFlag);
	int MrFileTruncate(char* pszFile, ULONG ulSize);
	ULONG MrFileLseek(short sWhence, ULONG ulOffset);
	int MrFileMmap(int iProt, int iFlag, ULONG ulSize);
	int MrFileFcntl(short sType, short sWhence, ULONG ulStart, ULONG ulLength, int iCmd);

	virtual int MrFileRead(UCHAR* puszLine, UINT uiLength, bool bProc);
	virtual int MrFileWrite(UCHAR* puszLine, UINT uiLength, bool bProc);
	virtual void MrFileMmapGet(ULONG ulOffset, UCHAR* puszLine, UINT uiLength, bool bProc);
	virtual void MrFileMmapPut(ULONG ulOffset, UCHAR* puszLine, UINT uiLength, bool bProc);

protected:
	void* m_pFile;
	ULONG m_ulSize;

private:
	int m_iFile;

};

#endif /* _MRFILE_H */
